#include "libmri.h"

void calib3d_matrix_size (int& m, int& n, int *csize, int *ksize)
{
	int cs1 = csize[0], cs2 = csize[1], cs3 = csize[2], nch = csize[3];
	int ks1 = ksize[0], ks2 = ksize[1], ks3 = ksize[2];

	m = (cs1-ks1+1)*(cs2-ks2+1)*(cs3-ks3+1);
	n = ks1*ks2*ks3*nch;
}

void calib3d_matrix (cplxf *A, cplxf *calib, int *csize, int *ksize)
{
	int cs1 = csize[0], cs2 = csize[1], cs3 = csize[2], nch = csize[3];
	int ks1 = ksize[0], ks2 = ksize[1], ks3 = ksize[2];

	int m1, m2, m3, m = (m1 = cs1-ks1+1)*(m2 = cs2-ks2+1)*(m3 = cs3-ks3+1);

	for (int i3 = 0; i3 < m3; ++i3)
		for (int i2 = 0; i2 < m2; ++i2)
			for (int i1 = 0; i1 < m1; ++i1)
			{
				int i = i1 + m1*(i2 + m2*i3);

				for (int ch = 0; ch < nch; ++ch)
					for (int j3 = 0; j3 < ks3; ++j3)
						for (int j2 = 0; j2 < ks2; ++j2)
							for (int j1 = 0; j1 < ks1; ++j1)
							{
								int j = j1 + ks1*(j2 + ks2*(j3 + ks3*ch));

								int c1 = i1+j1, c2 = i2+j2, c3 = i3+j3;
								int cidx = c1 + cs1*(c2 + cs2*(c3 + cs3*ch));
								A[i + m*j] = calib [cidx];
							}
			}
}


